//package com.xiong.springsecurity.config;
//
//import com.xiong.springsecurity.filter.JwtAuthenticationTokenFilter;
//import com.xiong.springsecurity.handle.AuthenticationEntryPointImpl;
//import lombok.RequiredArgsConstructor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.config.annotation.web.servlet.configuration.WebMvcSecurityConfiguration;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.web.AuthenticationEntryPoint;
//import org.springframework.security.web.access.AccessDeniedHandler;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//import org.springframework.web.filter.CorsFilter;
//
///**
// * <p>
// *
// * @author XiongDa
// * @version 1.0.0
// * @belongsProject: SpringSecurity
// * @belongsPackage: com.xiong.springsecurity.config
// * @since 2023/6/14 11:10
// **/
//@Configuration
//// 对 @PreAuthorize、@PostAuthorize、@PreFilter和@PostFilter支持
//@EnableGlobalMethodSecurity(prePostEnabled = true)
//public class SecurityConfigOld extends WebSecurityConfigurerAdapter {
//
//    @Autowired
//    private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
//
//    @Autowired
//    private AuthenticationEntryPoint authenticationEntryPoint;
//
//    @Autowired
//    private AccessDeniedHandler accessDeniedHandler;
//
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        http
//                //关闭csrf
//                .csrf().disable()
//                //不通过Session获取SecurityContext
//                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
//                .and()
//                .authorizeRequests()
//                // 对于登录接口 允许匿名访问, 也就是没登入可访问, 登入了不可访问
//                .antMatchers("/user/login").anonymous()
//                // permitAll() 放行
//                .antMatchers("/test").permitAll()
//                // 除上面外的所有请求全部需要鉴权认证
//                .anyRequest().authenticated();
//
//        // 把自己定义的过滤器加在 UsernamePasswordAuthenticationFilter 过滤器 前面
//        http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
//
//        http.exceptionHandling()
//                // 自定义认证异常处理
//                .authenticationEntryPoint(authenticationEntryPoint)
//                // 自定义授权异常处理
//                .accessDeniedHandler(accessDeniedHandler);
//
//        //允许跨域
//        http.cors();
//    }
//
//    @Bean
//    public PasswordEncoder passwordEncoder(){
//        return new BCryptPasswordEncoder();
//    }
//
//    @Bean
//    @Override
//    public AuthenticationManager authenticationManagerBean() throws Exception {
//        return super.authenticationManagerBean();
//    }
//
//}
